package splitter;

import java.util.HashMap;
import java.util.Map;

/**
 * 表示代码块的类
 */
public class CodeChunk {
    private String content;
    private ChunkMetadata metadata;

    /**
     * 创建一个新的代码块
     * 
     * @param content 代码内容
     * @param metadata 元数据
     */
    public CodeChunk(String content, ChunkMetadata metadata) {
        this.content = content;
        this.metadata = metadata;
    }

    /**
     * 创建一个新的代码块
     * 
     * @param content 代码内容
     * @param startLine 开始行
     * @param endLine 结束行
     * @param language 语言
     * @param filePath 文件路径
     */
    public CodeChunk(String content, int startLine, int endLine, String language, String filePath) {
        this.content = content;
        this.metadata = new ChunkMetadata(startLine, endLine, language, filePath);
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public ChunkMetadata getMetadata() {
        return metadata;
    }

    public void setMetadata(ChunkMetadata metadata) {
        this.metadata = metadata;
    }

    /**
     * 代码块元数据类
     */
    public static class ChunkMetadata {
        private int startLine;
        private int endLine;
        private String language;
        private String filePath;
        private Map<String, Object> additionalMetadata;

        /**
         * 创建一个新的代码块元数据
         * 
         * @param startLine 开始行
         * @param endLine 结束行
         * @param language 语言
         * @param filePath 文件路径
         */
        public ChunkMetadata(int startLine, int endLine, String language, String filePath) {
            this.startLine = startLine;
            this.endLine = endLine;
            this.language = language;
            this.filePath = filePath;
            this.additionalMetadata = new HashMap<>();
        }

        public int getStartLine() {
            return startLine;
        }

        public void setStartLine(int startLine) {
            this.startLine = startLine;
        }

        public int getEndLine() {
            return endLine;
        }

        public void setEndLine(int endLine) {
            this.endLine = endLine;
        }

        public String getLanguage() {
            return language;
        }

        public void setLanguage(String language) {
            this.language = language;
        }

        public String getFilePath() {
            return filePath;
        }

        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }

        public Map<String, Object> getAdditionalMetadata() {
            return additionalMetadata;
        }

        public void setAdditionalMetadata(Map<String, Object> additionalMetadata) {
            this.additionalMetadata = additionalMetadata;
        }

        public void addMetadata(String key, Object value) {
            this.additionalMetadata.put(key, value);
        }

        public Object getMetadata(String key) {
            return this.additionalMetadata.get(key);
        }
    }
}